using System;
using System.Reflection;

namespace Kopernikus.Parsing.GenericActions
{
    internal class ReflectedSemanticActionWithArrayParameter<TParser, S> : ReflectedSemanticAction<TParser, S>
    {
        private readonly Type m_elementType;

        public ReflectedSemanticActionWithArrayParameter(MethodInfo method, Type elementType,
                                                         ISemanticActionParametersFixup fixup)
            : base(method, fixup)
        {
            m_elementType = elementType;
        }

        protected override object[] MakeArgumentArray(S[] args)
        {
            Array arguments = Array.CreateInstance(m_elementType, args.Length);
            Array.Copy(args, arguments, args.Length);
            return new object[] {arguments};
        }
    }
}